/**
 * 
 *汇付天下有限公司
 * Copyright (c) 2006-2013 ChinaPnR,Inc.All Rights Reserved.
 */
package com.zx.screener.service.userCenter.service.impl;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.zx.screener.dao.userCenter.OperatorDAO;
import com.zx.screener.service.userCenter.constant.UserCenterEnum;
import com.zx.screener.service.userCenter.exception.UserCenterServiceException;
import com.zx.screener.service.userCenter.model.Operator;
import com.zx.screener.service.userCenter.service.LoginService;

/**
 * 
 * @author zhanghaijie
 * @version $Id: LoginServiceImpl.java, v 0.1 2013-3-7 上午10:55:43 zhanghaijie Exp $
 */
public class LoginServiceImpl implements LoginService {

    private static final Logger logger = Logger.getLogger(LoginServiceImpl.class);

    private OperatorDAO         operatorDAO;

    /** 
     * @see com.zx.screener.service.userCenter.service.LoginService#Login(java.lang.String, java.lang.String)
     */
    @Override
    public Operator Login(String loginNum, String pwd) throws UserCenterServiceException {
        try {
            Operator operator = operatorDAO.findOperatorByCertNum(loginNum);
            if (StringUtils.equals(operator.getLoginInfo().get(0).getPassword(), pwd)) {
                return operator;
            }
            logger.warn("password does not match" + loginNum);
        } catch (Exception e) {
            logger.warn("User does not exist" + loginNum, e);
        }
        throw new UserCenterServiceException(UserCenterEnum.LOGIN_ERROR.getErrorCode());
    }

    public void setOperatorDAO(OperatorDAO operatorDAO) {
        this.operatorDAO = operatorDAO;
    }

}
